<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var genParenthesis = (n) => {
      let set = new Set(['()'])
      for (let i = 2; i <= n; i++) {
        let next = new Set()
        for (const s of set) {
          for (let j = 0; j <= s.length; j++) {
            next.add(s.slice(0, j) + '()' + s.slice(j))
          }
        }
        set = next
      }
      return [...set]
    }
    console.log(genParenthesis(3))
  </script>
</body>

</html>